package com.example.mywechatprogram.service;

import com.example.mywechatprogram.entity.Response;
import com.example.mywechatprogram.entity.Sculpture;
import com.example.mywechatprogram.mapper.SculptureMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class SculptureService {
    @Autowired
    SculptureMapper sculptureMapper;
    public Response request(){
        try {
            List<Sculpture> list = sculptureMapper.request();
            if (list!=null)return new Response(Response.SERVICE_RUN_SUCCESSFULLY,list,"头像列表获取成功");
            else return new Response(Response.SERVICE_RUN_SUCCESSFULLY,null,"头像列表获取失败");
        }catch (Exception e){
            return new Response(Response.SERVICE_RUN_FIELD,null,"内部错误");
        }
    }
    public Response query(String UUID){
        try {
            String imageUrl = sculptureMapper.query(UUID);
            return new Response(Response.SERVICE_RUN_SUCCESSFULLY,imageUrl,"请求头像成功");
        }catch (Exception e){
            return new Response(Response.SERVICE_RUN_FIELD,null,"请求头像失败");
        }
    }

    public Response update(String UUID,int id){
        try {
            int index=sculptureMapper.update(UUID,id);
            if(index==1)return new Response(Response.SERVICE_RUN_SUCCESSFULLY,null,"头像更改成功");
            else return new Response(Response.SERVICE_RUN_SUCCESSFULLY,null,"头像更改失败");
        }catch (Exception e){
            return new Response(Response.SERVICE_RUN_FIELD,null,"内部错误");
        }
    }
}
